﻿using System;
using System.Windows.Data;
using AzureDiagMon.Common.Dtos;
using AzureDiagMon.Common.Helpers;

namespace AzureDiagMon.Common.Converters
{
    public class WadLogLevelToIconImageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                var level = value as int?;
                if (level == null)
                    return value;

                var traceLevel = (WadLogLevel)(level.Value);

                string fileName = null;

                switch (traceLevel)
                {
                    case WadLogLevel.Error:
                        fileName = "Error.png";
                        break;
                    case WadLogLevel.Warning:
                        fileName = "Warning.png";
                        break;
                    case WadLogLevel.Info:
                        fileName = "Info.png";
                        break;
                    case WadLogLevel.Verbose:
                        break;
                }

                if (String.IsNullOrEmpty(fileName))
                    return value;

                return ImageHelper.ImageFromFileName(fileName);
            }
            catch
            {
                return value;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Not implemented
            return null;
        }
    }
}
